# -*- coding: utf-8 -*-
"""
@Time    : 2024/7/17 09:23 
@Author  : ZhangShenao 
@File    : 3.使用OpenAI原生的EmbeddingAPI.py
@Desc    : 使用OpenAI原生的EmbeddingAPI

API地址:https://platform.openai.com/docs/api-reference/embeddings/create?lang=python
"""
import os

import dotenv
from openai import OpenAI

# 加载环境变量
dotenv.load_dotenv()

# 创建OpenAI客户端
client = OpenAI(base_url=os.getenv('OPENAI_API_BASE'))

resp = client.embeddings.create(
    model='text-embedding-3-large',
    input='The food was delicious and the waiter...',
    encoding_format="float",
    dimensions=1024,
)

print(f'dimension of embedding is {len(resp.data[0].embedding)}')
